<template>
    <div class="goodsinfobox">
        <transition
        @before-enter="beforeEnter"
        @enter="enter"
        @after-enter="afterEnter">
         <div class="ball" v-show="ballFlag"></div>
        </transition>


        <div class="mui-card">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
					<swiper :lunboList='lunbotuList' :isfull='false'></swiper>
					</div>
				</div>
			</div>

            <div class="mui-card">
				<div class="mui-card-header"><h1>{{goodsList.title}}</h1></div>
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<p>市场价：<del>￥{{goodsList.market_price}}</del> <span class="now">￥{{goodsList.sell_price}}</span></p>
                        <p >购买数量 <numberbox @getCount="getselectCount" :getmunMax="goodsList.stock_quantity"></numberbox></p>
                        <div class="but-box">
                            <mt-button type="primary" size='small'>立即购买</mt-button>
                            <mt-button type="danger" size='small' @click="ballShow">加入购物车</mt-button>
                        </div>
					</div>
				</div>
			</div>

            <div class="mui-card">
				<div class="mui-card-header">商品参数</div>
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<p>商品编号：{{goodsList.goods_no}}</p>
                        <p>库存件数：{{goodsList.stock_quantity}}</p>
                        <p>上架时间：{{goodsList.add_time|dataFormat}}</p>
					</div>
				</div>
				<div class="mui-card-footer">
                        <mt-button type="primary" size='large' plain @click="getjianjie(id)">图文介绍</mt-button>
                        <mt-button type="danger" size='large' plain @click="getxiangqing(id)">商品评论</mt-button>
                </div>
			</div>
    </div>
</template>

<script>

 import swiper from '../subcoment/swiper.vue'


 import numberbox from '../subcoment/numberbox.vue'
export default {
    
    data() {
        return {
            lunbotuList:[],
           id:this.$route.params.id,
           goodsList:{},
           ballFlag:false,
           selectCount:1
        }
    },
    created() {
        this.getlunbo(),
        this.getgoodsinfo()
    },
    methods: {
        getlunbo(){
            this.$http.get('http://www.liulongbin.top:3005/api/getthumimages/'+this.id).then(result=>{
                if(result.body.status==0){
                    result.body.message.forEach(item => {
                        item.img=item.src
                    });
                    this.lunbotuList=result.body.message
                    // console.log(this.lunbotuList)
                }
            })
        },
        getgoodsinfo(){
            this.$http.get('http://www.liulongbin.top:3005/api/goods/getinfo/'+this.id).then(result=>{
                if(result.body.status==0){
                    this.goodsList=result.body.message[0]
                    // console.log(this.goodsList)
                }
            })
        },
        getjianjie(id){
            // 点击跳转到简介
            this.$router.push({name:'goodsjianjie',params:{id}})

        },
        getxiangqing(id){
            // 点击跳转到详情
            this.$router.push({name:'goodsxiangqing',params:{id}})
        },
        ballShow(){
            // 添加到购物车
            this.ballFlag=!this.ballFlag
            var goodsinfo={
                id:this.id,
                count:this.selectCount,
                price:this.goodsList.sell_price,
                selected:true
            }
            this.$store.commit("addTocar",goodsinfo)
        },
        beforeEnter(el){
            el.style.transform="translate(0,0)"
        },
        enter(el,done){
            el.offsetWidth;
            el.style.transform="translate(99px,320px)";
            el.style.transition="all 1s cubic-bezier(.4,-0.3,1,.68)";
            done()
        },
        afterEnter(el){
            this.ballFlag=!this.ballFlag
        },
        getselectCount(count){
            this.selectCount=count
            console.log(this.selectCount)
        }



    },
    components:{
        swiper,
        numberbox
    }
}
</script>

<style lang="scss" scoped>
.goodsinfobox{
    background-color: #eeeeee;
    overflow: hidden;
    .ball{
        background-color: red;
        width: 15px;
        height: 15px;
        border-radius: 50%;
        position: absolute;
        z-index: 999;
        left: 140px;
        top: 395px;
       
    }
    
}
.mui-card{
    .mui-card-header{
        border: 1px solid #cccccc;
        h1{
            font-size: 16px;
        }
    }
    .mui-card-content-inner{
        .now{
            color: red;
            font-weight: 700;
        }
    }
    .mui-card-footer{
        display: block;
        button{
            margin: 15px 0;
        }
    }
}
</style>
